package com.example.lucene.test;

import com.example.lucene.model.KnowledgeBase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author yanggld
 * @Date 2019/5/24-17:09
 * @Description
 */
public class LuceneTester {

	String indexDir = "index";
	Indexer indexer;

	public static void main(String[] args) {
		LuceneTester tester;
		try {
			tester = new LuceneTester();
			tester.createIndex();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void createIndex() throws IOException{
		indexer = new Indexer(indexDir);
		long startTime = System.currentTimeMillis();
		List<KnowledgeBase> list = new ArrayList<>();
		KnowledgeBase base = new KnowledgeBase();
		base.setContent("好好学习");
		list.add(base);
		KnowledgeBase base1 = new KnowledgeBase();
		base1.setContent("天天学习 ");
		list.add(base1);
		indexer.createIndex(list);
		long endTime = System.currentTimeMillis();
		indexer.close();
		System.out.println(" File indexed, time taken: "
				+(endTime-startTime)+" ms");
	}
}